package com.example.win.android_banduyujia.peopleactivity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;

import java.util.ArrayList;

/**
 * Created by Win on 2015/9/2.
 */
public class ListviewAdapter extends BaseAdapter{

    private  Context  context;
    private  ArrayList<String>  lists;

    public ListviewAdapter(Context context, ArrayList<String> lists) {
       this.context = context;
       this.lists = lists;
    }

    @Override
    public int getCount() {
        if(null != lists){
            return lists.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if(null != lists){
            return lists.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder  viewHolder = null;
        if(convertView == null && lists.size() !=0){
            viewHolder = new ViewHolder();
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.view_spinner_item, null);
            viewHolder.textView= (TextView) convertView.findViewById(R.id.layout_text_view_item);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
            viewHolder.textView.setText(lists.get(position));
        }
        return null;
    }

    public class ViewHolder{
        TextView  textView;
    }
}
